package com.videoweb.controller;


import com.videoweb.annotation.Anonymous;
import com.videoweb.config.QiNiuConfig;
import com.videoweb.utils.AjaxResult;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
public class videoTokenController {
    @Autowired
    QiNiuConfig qiNiuConfig;

    @RequestMapping("/gettoken")
    public String gettoken(){
//        return qiNiuConfig.videoUploadToken();
        return qiNiuConfig.uploadToken();
    }



    @RequestMapping("/getVideoToken")
    public AjaxResult videoUploadToken() {
//        return qiNiuConfig.videoUploadToken();

        qiNiuConfig.videoUploadToken();
        return AjaxResult.success().put("token",qiNiuConfig.videoUploadToken());
    }
//    }
//    @RequestMapping("/getVideoToken")
//    public String videoUploadToken(){
////        return qiNiuConfig.videoUploadToken();
//        return qiNiuConfig.videoUploadToken();
//    }


    @RequestMapping("/getImageToken")
    public AjaxResult getImageToken(){
//        return qiNiuConfig.videoUploadToken();
        return AjaxResult.success().put("token",qiNiuConfig.imageUploadToken());

//        return qiNiuConfig.imageUploadToken();
    }




    @GetMapping("/{fileId}")
    public void getUUid(HttpServletRequest request, HttpServletResponse response, @PathVariable Long fileId) throws IOException {

     /*   String ip = request.getHeader("referer");
        if (!LocalCache.containsKey(ip)) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }*/
        // 如果不是指定ip调用的该接口，则不返回
//        传过来的是视频的ID，但是根据视频的ID查找文件表中的key将其拼接起来


    }
}
